package com.cat.model.web.action.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alonew.json.JSONArray;
import com.alonew.json.JSONException;
import com.alonew.json.JSONObject;
import com.cat.model.biz.logic.BasLogic;
import com.cat.model.common.model.common.BasConfigVO;
import com.cat.model.common.util.ErrorCode;
import com.cat.model.web.action.base.BaseAction;

public class BasConfigAction extends BaseAction{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1866168521089838580L;
	private String name;
	
	@Autowired
	private BasLogic basLogic;
	
	public void configValue(){
		List<BasConfigVO> list = basLogic.getBasConfigByName(name);
		ErrorCode code = ErrorCode.OK;
		JSONObject json = code.responseJSON();
		try {
			JSONArray array = new JSONArray();
			if(null == list || list.size() <= 0){
				json.put("data", array);
				print(json.toString());
				return;
			}
			for(BasConfigVO item : list){
				JSONObject infoJson = new JSONObject();
				infoJson.put("name", item.getName());
				infoJson.put("configValue", item.getConfigValue());
				infoJson.put("description", item.getDescription());
				
				array.put(infoJson);
			}
						
			json.put("data", array);
		} catch (JSONException e) {
			print(ErrorCode.SERVER_ERROR.response());
			return;
		}
		
		print(json.toString());
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
